import type {ComponentConfig, ProjectStructure} from "@/lib/types"
import {generateBasicComponent} from "@/lib/templates/basic-component"
import {generateFormComponent} from "@/lib/templates/form-component"
import {generateLayoutComponent} from "@/lib/templates/layout-component"
import {generateDataComponent} from "@/lib/templates/data-component"
import {generateNavigationComponent} from "@/lib/templates/navigation-component"

export class CodeGenerator {
    static initializeProjectStructure(): ProjectStructure {
        return {
            rootDir: "src",
            files: [
                {path: "public/favicon.ico", content: "", type: "file"},
                {path: "src/assets/logo.png", content: "", type: "file"},
                {path: "src/components/DashboardHeader.vue", content: "", type: "file"},
                {path: "src/components/DashboardSidebar.vue", content: "", type: "file"},
                {path: "src/components/RecentActivityList.vue", content: "", type: "file"},
                {path: "src/components/ChartComponent.vue", content: "", type: "file"},
                {path: "src/views/DashboardView.vue", content: "", type: "file"},
                {path: "src/layouts/DefaultLayout.vue", content: "", type: "file"},
                {path: "src/router/index.ts", content: "", type: "file"},
                {path: "src/stores/useDashboardStore.ts", content: "", type: "file"},
                {path: "src/utils/apiClient.ts", content: "", type: "file"},
                {path: "src/styles/globals.css", content: "", type: "file"},
                {path: "src/types/custom.d.ts", content: "", type: "file"},
                {path: "src/App.vue", content: "", type: "file"},
                {path: "src/main.ts", content: "", type: "file"},
                {path: "vite.config.ts", content: "", type: "file"},
                {path: "tsconfig.json", content: "", type: "file"},
                {path: "tailwind.config.js", content: "", type: "file"},
                {path: "postcss.config.js", content: "", type: "file"},
                {path: "package.json", content: "", type: "file"}
            ]
        }
    }

    static generate(config: ComponentConfig, projectContext?: ProjectStructure): string {
        const {type, context = projectContext} = config

        // 根据组件类型选择模板
        switch (type) {
            case "form":
                return generateFormComponent(config)
            case "layout":
                return generateLayoutComponent(config)
            case "data":
                return generateDataComponent(config)
            case "navigation":
                return generateNavigationComponent(config)
            case "basic":
            default:
                return generateBasicComponent({...config, context})
        }
    }
}
